﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.Text;
using System.Threading.Tasks;
using System.Web.Security;
using Application.Services;
using DistributedServices.Core.ErrorHandlers;
using DistributedServices.MembershipModule.InstanceProvider;
using Domaine.MembershipModule.DTO;
using Domaine.Entity;

namespace DistributedServices.MembershipModule
{
    [ApplicationErrorHandlerAttribute()]
    [UnityInstanceProviderServiceBehavior()]  
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
    public class MembershipService : IMembershipService
    {

        #region Members

        IAppMembershipProvider _appMembershipProvider;

        #endregion

        #region Constructor

        /// <summary>
        /// Create a new instance of banking module service
        /// </summary>
        /// <param name="bankAppService">The bank application service dependency</param>
        public MembershipService(IAppMembershipProvider appMembershipProvider)
        {
            if (appMembershipProvider == null)
                throw new ArgumentNullException("appMembershipProvider");
            _appMembershipProvider = appMembershipProvider;
        }
        #endregion



        public Domaine.Entity.Membership CreateUser( Domaine.Entity.Membership newMemnber)  
        {
            return _appMembershipProvider.AddNewMember(newMemnber);
        }

        public  bool ValidateUser(string username, string password)
        {
            return _appMembershipProvider.ValidateUser(username, password);
        }

        public IEnumerable<Domaine.Entity.Membership> GetAllUsers(int pageIndex, int pageSize )
        {
            throw new NotImplementedException();
        }

        public Domaine.Entity.Membership GetUser(string username, bool userIsOnline)
        {
            return  System.Web.Security.Membership.GetUser(username, userIsOnline).ToMember();
        }

        public bool DeleteUser(string username, bool deleteAllRelatedData)
        {
            return System.Web.Security.Membership.DeleteUser(username,  deleteAllRelatedData);
        }

    }
}
